# -*- coding: utf-8 -*-
from __future__ import unicode_literals

__author__ = 'zhengkc'

from django.db import models

FIELD_STATUS_CHOICE = (
    ('1', u'可用的'),
    ('0', u'不可用'),
    ('-1', u'已删除')
)


# PROJECT_STATUS_CHOICE = (
#     ('1', u'已发布'),
#     ('0', u'未发布'),
#     ('-1', u'已删除')
# )
# SYS_CONFIG_TYPE = (
#     ('ENVIR', u'环境配置'),
#     ('OTHER', u'其他'),
# )
#
# USER_CONFIG_IDEN = (
#     ('TEACHER', u'老师'),
#     ('STUDENT', u'学生'),
#     ('MANAGER', u'管理员')
# )
#
#
class Product(models.Model):
    """产品"""
    name = models.CharField(verbose_name=u'产品名称', max_length=32)
    zt_product_id = models.IntegerField(verbose_name=u'禅道项目ID', default=0)
    description = models.CharField(validators=u'产品描述', max_length=256)

    class Meta:
        verbose_name = u'产品'
        verbose_name_plural = u'产品'

    def __unicode__(self):
        return u'%s' % (self.name)


class EnvirConfig(models.Model):
    """环境配置"""
    product = models.ForeignKey(Product, verbose_name=u'所属产品', related_name='envir_configs')
    name = models.CharField(verbose_name=u'环境配置名称', max_length=32)
    domain = models.CharField(verbose_name=u'域名', max_length=64)
    db_config = models.CharField(verbose_name=u'数据库配置', max_length=256)
    description = models.CharField(validators=u'产品描述', max_length=256)
    status = models.CharField(verbose_name=u'环境配置状态', choices=FIELD_STATUS_CHOICE,max_length=20)

    class Meta:
        verbose_name = u'环境配置'
        verbose_name_plural = u'环境配置'

    def __unicode__(self):
        return u'%s' % (self.name)


class Api(models.Model):
    """接口列表"""
    product = models.ForeignKey(Product, verbose_name=u'所属项目', related_name='apis', blank=True)
    name = models.CharField(verbose_name=u'接口名称', max_length=50)
    uri = models.CharField(verbose_name=u'URI', max_length=256)
    description = models.CharField(verbose_name=u'接口描述', max_length=256)
    update_time = models.DateTimeField(verbose_name=u'更新时间', auto_now=True)

    class Meta:
        verbose_name = u'接口列表'
        verbose_name_plural = u'接口列表'

    def __unicode__(self):
        return u'%s' % (self.name)


class ApiArgs(models.Model):
    """接口参数"""
    api = models.ForeignKey(Api, verbose_name=u'所属接口')
    args_name = models.CharField(verbose_name=u'参数名称', max_length=50)
    args_data_type = models.CharField(verbose_name=u'参数数据类型', max_length=255)
    check_type = models.CharField(verbose_name=u'验证方式', max_length=255)
    check_value = models.CharField(verbose_name=u'验证值', max_length=255)
    description = models.CharField(verbose_name=u'接口描述', max_length=255)

    class Meta:
        verbose_name = u'接口参数'
        verbose_name_plural = u'接口参数'

    def __unicode__(self):
        return u'%s' % (self.args_name)


class ApiResponses(models.Model):
    """接口响应值"""
    api = models.ForeignKey(Api, verbose_name=u'所属接口')
    field = models.CharField(verbose_name=u'响应值名称', max_length=255)
    type = models.CharField(verbose_name=u'响应值类型', max_length=25)
    description = models.CharField(verbose_name=u'接口描述', max_length=255)

    class Meta:
        verbose_name = u'接口响应值'
        verbose_name_plural = u'接口响应值'

    def __unicode__(self):
        return u'%s' % (self.field)


class ApiResponsesCodes(models.Model):
    """响应状态码"""
    api = models.ForeignKey(Api, verbose_name=u'所属接口')
    code = models.CharField(verbose_name=u'状态码', max_length=25)
    description = models.CharField(verbose_name=u'接口描述', max_length=255)

    class Meta:
        verbose_name = u'响应状态码'
        verbose_name_plural = u'响应状态码'

    def __unicode__(self):
        return u'%s' % (self.code)


class Project(models.Model):
    """项目"""
    product = models.ForeignKey(Product, verbose_name=u'所属产品', related_name='projects')
    name = models.CharField(verbose_name=u'项目名称', max_length=32)
    api = models.ManyToManyField(Api, verbose_name=u'相关接口', blank=True, related_name='project')
    description = models.CharField(verbose_name=u'项目描述', max_length=256)
    create_time = models.DateTimeField(verbose_name=u'创建时间', auto_now_add=True)

    class Meta:
        verbose_name = u'项目'
        verbose_name_plural = u'项目'

    def __unicode__(self):
        return u'%s' % (self.name)
